package com.ipDev.moyvSys.controller.emp;

import com.ipDev.moyvSys.domain.dto.BookDTO;
import com.ipDev.moyvSys.domain.vo.BookVO;
import com.ipDev.moyvSys.service.IBookService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import com.ipDev.moyvSys.utils.Code;
import com.ipDev.moyvSys.utils.Result;

@RestController
@RequestMapping("/emp/book")
@Api(value = "职工的书本相关接口")
@Slf4j
@RequiredArgsConstructor
public class EmpBookController {
    private final IBookService bookService;


    @PostMapping("/add")
    public Result<Void> addBook(@RequestBody BookDTO bookDTO) {
        //TODO 新增书本 问题 选项的操作都可能涉及图片上传 需要统一改造
        log.info("新增书本:{}", bookDTO);
        bookService.saveOne(bookDTO);
        return Result.success(Code.SAVE_OK,"finished",null);
    }

    @GetMapping("/list")
    public Result<List<BookVO>> listEnableBook() {
        log.info("职工查看启用的书本");
        return Result.success(Code.GET_OK,"启用的书本",bookService.listEnableBook());
    }

    @GetMapping("/listAll")
    public Result<List<BookVO>> listAllBook() {
        log.info("职工查看所有书本");
        return Result.success(Code.GET_OK,"启用的书本",bookService.listAllBook());
    }

    @DeleteMapping("/del/{id}")
    public Result<Void> delByBookId(@PathVariable Integer id) {
        log.info("职工根据id删除单本书籍:{}", id);
        bookService.delByBookId(id);
        return Result.success(Code.DELETE_OK,"finished",null);
    }

    @DeleteMapping("/del")
    public Result<Void> delByBookIds(@RequestBody List<Integer> bookIds) {
        log.info("职工批量删除书籍:{}", bookIds);
        bookService.delByBookIds(bookIds);
        return Result.success(Code.DELETE_OK,"finished",null);
    }

    @PutMapping("/search")
    public Result<List<BookVO>> search(@RequestBody BookDTO bookDTO) {
        log.info("职工查询书籍:{}", bookDTO);
        return Result.success(Code.GET_OK,"finished",bookService.search(bookDTO));
    }

    @PostMapping("/update")
    public Result<Void> updateBook(@RequestBody BookDTO bookDTO) {
        log.info("职工修改书籍信息:{}", bookDTO);
        bookService.updateBook(bookDTO);
        return Result.success(Code.UPDATE_OK,"finished",null);
    }

}
